package com.eedi.framework.event.framework.event;

import cn.hutool.core.collection.CollUtil;
import com.eedi.framework.common.event.annotations.event.EediEventPoint;
import com.eedi.framework.common.util.object.BeanUtils;
import com.eedi.framework.event.controller.vo.SysEventConsumerCreateReq;
import com.eedi.framework.event.controller.vo.SysEventConsumerResp;
import com.eedi.framework.event.controller.vo.SysEventObsOrgResp;
import com.eedi.framework.event.convert.SysEventConsumerConvert;
import com.eedi.framework.event.convert.SysEventObsOrgConvert;
import com.eedi.framework.event.core.api.*;
import com.eedi.framework.event.service.SysEventService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Collection;
import java.util.List;

@Service
@Slf4j
public class EventDataApiFacade implements EventDataApi {
    @Resource
    SysEventService sysEventService;

    @Override
    public List<EediObsOrgInfo> getObserverByPoint(EediEventPoint point) {
        List<SysEventObsOrgResp> obsOrg = sysEventService.getObsOrg(point);
        return obsOrg.stream().map(SysEventObsOrgConvert.INSTANCE::convert).toList();
    }

    @Override
    public void createConsumer(Collection<EediConsumerCreateReq> reqs) {
        if (CollUtil.isEmpty(reqs)) {
            return;
        }
        List<SysEventConsumerCreateReq> createReqs =
                reqs.stream().map(SysEventConsumerConvert.INSTANCE::convert).toList();
        sysEventService.createConsumer(createReqs);

    }

    @Override
    public List<EediConsumerResp> getConsumerInfoByCreated(QueryConsumerInfoReq req) {
        List<SysEventConsumerResp> consumerOnCreated = sysEventService.getConsumerOnCreated();
        return BeanUtils.toBean(consumerOnCreated, EediConsumerResp.class);
    }

    @Override
    public void statusToHandle(String sysEventConsumerId) {
        sysEventService.setStatusToHandle(sysEventConsumerId);
    }

    @Override
    public void statusToException(String sysEventConsumerId, String exception) {
        sysEventService.setStatusToException(sysEventConsumerId, exception);
    }

    @Override
    public void statusToSubmitted(String sysEventConsumerId, String msg) {
        sysEventService.setStatusToSubmitted(sysEventConsumerId, msg);
    }


}
